package br.com.fafica.exemplario.control;

import java.sql.SQLException;

import br.com.fafica.exemplario.model.dao.Banco;
import br.com.fafica.exemplario.model.dao.Factory;
import br.com.fafica.exemplario.model.dao.InterfaceUserDAO;
import br.com.fafica.exemplario.view.shell.Principal;

public class ControllerShell implements InterfaceController {
	
	private Principal tela;
	private InterfaceUserDAO banco;
	
	public ControllerShell() {
		tela = new Principal();
	}

	public void inicializar() {
		tela.welcome();
		int opcao = tela.menuBanco();
		try {
			switch (opcao) {
			case 1:
				Factory.criarBanco(Banco.ARRAY);
				banco = Factory.getBanco();
				break;

			case 2:
				Factory.criarBanco(Banco.SQLITE);
				banco = Factory.getBanco();
				break;

			default:
				break;
			}
		} catch (ClassNotFoundException e) {
			tela.erro("Erro no Banco de Dados.");
			e.printStackTrace();
		} catch (SQLException e) {
			tela.erro("Erro no SQL.");
			e.printStackTrace();
		}
		
		opcao = tela.menu();
		if (opcao == 1) {
			testarUserDAO();
		}
	}

	public void testarUserDAO() {
		try {
			tela.exibirTodos(banco.listeTodos());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
